package com.example.mobile2021606163crw0506;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.renderscript.ScriptGroup;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private EditText edtTxtMainInput;
    private Button btnMainIE;
    private Button btnMainCall;
    private Button btnMainCamera;
    private Button btnMainMap;
    private Intent intent;
    private String input;
    private Uri uri;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    private void initView() {
        edtTxtMainInput = (EditText) findViewById(R.id.edtTxtMainInput);
        btnMainIE = (Button) findViewById(R.id.btnMainIE);
        btnMainIE.setOnClickListener(this);
        btnMainCall = (Button) findViewById(R.id.btnMainCall);
        btnMainCall.setOnClickListener(this);
        btnMainCamera = (Button) findViewById(R.id.btnMainCamera);
        btnMainCamera.setOnClickListener(this);
        btnMainMap = (Button) findViewById(R.id.btnMainMap);
        btnMainMap.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btnMainIE:
                input = edtTxtMainInput.getText().toString().trim();
                uri =   Uri.parse(input);
                intent = new Intent(Intent.ACTION_VIEW,uri);
                startActivity(intent);
                break;
            case R.id.btnMainCall:
                input = edtTxtMainInput.getText().toString().trim();
                uri =   Uri.parse("Tel:"+input);
                intent = new Intent(Intent.ACTION_DIAL,uri);
                startActivity(intent);
                break;
            case R.id.btnMainCamera:
                intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                startActivityForResult(intent,1);
                break;
            case R.id.btnMainMap:
                input = edtTxtMainInput.getText().toString().trim();
                uri = Uri.parse("geo:"+input);
                intent = new Intent(Intent.ACTION_VIEW,uri);
                startActivity(intent);
                break;
        }
    }
}